package cn.fenqing.arithmetic.leetcode;

import cn.fenqing.arithmetic.leetcode.commons.ListNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Theme234 {

    public static void main(String[] args) {
        //[1,2,2,1]
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2, node1);
        ListNode node3 = new ListNode(2, node2);
        ListNode node4 = new ListNode(1, node3);
        new Solution2().isPalindrome(node4);
    }

}
class Solution2 {
    public boolean isPalindrome(ListNode head) {
        //先转成List
        List<Integer> list = new ArrayList<>();
        toList(head, list);
        //再判断
        List<Integer> temp = new ArrayList<>(list);
        Collections.reverse(temp);
        return list.equals(temp);
    }
    public void toList(ListNode head, List<Integer> list) {
        if(head == null){
            return;
        }
        list.add(head.val);
        toList(head.next, list);
    }
}